package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/users")
    public int save(@RequestBody User user){
        return userService.save(user);
    }

    @DeleteMapping("/users/{userId}")
    public int delete(@PathVariable("userId") int userId){
        return userService.delete(userId);
    }

    @PutMapping("/users")
    public int update(@RequestBody User user){
        return userService.update(user);
    }

    @GetMapping("/users")
    public List<User> select(){
        return userService.select();
    }


}
